import axios from '@/utils/axios'

// 管理员相关API接口
export interface AdminInfo {
    admin_id: number
    admin_account: string
    admin_role: number
    admin_name: string
    status: number
    create_time: string
    last_login_time: string
    reset_password_time: string
}

export interface AdminListResponse {
    code: number
    msg: string
    data: {
        list: AdminInfo[]
        total: number
    }
}

export interface CurrentUserResponse {
    code: number
    msg: string
    data: {
        admin_id: number
        admin_account: string
        admin_role: number
        admin_name: string
    }
}

// 获取当前用户信息
export const getCurrentUser = (): Promise<CurrentUserResponse> => {
    const token = localStorage.getItem('token');

    return axios.get('/admin/current', {
        headers: { 'Authorization': `Bearer ${token}` }
    })
}

// 获取管理员列表
export const getAdminList = (params?: {
    page?: number
    size?: number
    keyword?: string
}): Promise<AdminListResponse> => {
    return axios.get('/admin/list', { params })
}

// 添加管理员
export const addAdmin = (data: {
    admin_account: string
    admin_password: string
    admin_role: number
    admin_name: string
    status: number
}): Promise<any> => {
    return axios.post('/admin/add', data)
}

// 编辑管理员
export const updateAdmin = (data: {
    admin_id: number
    admin_account: string
    admin_password?: string
    admin_role: number
    admin_name: string
    status: number
}): Promise<any> => {
    return axios.put('/admin/update', data)
}

// 删除管理员
export const deleteAdmin = (adminId: number): Promise<any> => {
    return axios.delete(`/admin/delete/${adminId}`)
}
